<?php
class kategori_Model extends CI_Model{
	
	
	 function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
	
	function getData($limit, $offset, $judul=""){
		$sql="SELECT * from tbl_kategori where nama like '%".$judul."%' order by id_kategori desc limit $offset, $limit";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->result_array();
		}else{
			return array();
		}
	}
	
	function get_detail_data($id){
		$sql="SELECT * from tbl_kategori where id_kategori='".$id."'";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->row_array();
		}else{
			return array();
		}
	}
	
	function getAllData(){
		$sql="SELECT * from tbl_kategori order by id_kategori desc";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->result_array();
		}else{
			return array();
		}
	}
	function count_all_num_rows($judul=""){
		$sql="SELECT * from tbl_kategori where nama like '%".$judul."%' ";
		//echo $sql;
		$query=$this->db->query($sql);
		return $query->num_rows();
		
	}
	
	function insert_data($judul){
		
		$data=array('nama'=>$judul);
		$insert=$this->db->insert('tbl_kategori',$data);
		return $insert;
	}
	
	function update_data($id,$judul){
		$data=array('nama'=>$judul);
		$this->db->where('id_kategori',$id);
		$update=$this->db->update('tbl_kategori',$data);
		return $update;
	}
	
	function delete_data($id){
		$data=array('id_kategori'=>$id);
		$this->db->where($data);
		$delete=$this->db->delete('tbl_kategori'); 
		return $delete;
	}
	
	function cek_client($id){
		$sql="SELECT * from tbl_client where id_kategori='".$id."'";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return true;
		}else{
			return false;
		}
	}
	
	
	

}
?>